<!DOCTYPE html>
<html>
<head>
	<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes" />
    <meta charset="utf-8">
    <title>收入支出计算器</title>
	
	<style type="text/css">
		input {
			width:15%;
		}
		table
		{
			border-collapse:collapse;
		}

		table,th, td
		{
			border: 1px solid black;
		}
	</style>
	<script type='text/javascript'>
		var defaulttable = "<tr><td>项目</td><td>人力</td><td>弹药</td><td>口粮</td><td>零件</td><td>核心</td><td>人形契约</td><td>装备契约</td><td>快速修复</td><td>采购币</td><td>快速建造</td><td>次数</td><td>删除</td></tr>"
		var table,pj,percent;
		var inputbox = document.getElementsByTagName("input");


		var data = {
			"自动恢复": Array(1440, 1440, 1440, 480, 0, 0, 0, 0, 0, 0, 7),
			"周常全勤": Array(7200, 8700, 8700, 4700, 6, 10, 14, 19, 5, 14, 1),
			"周常及格": Array(5350, 7350, 7350, 3850, 5, 9, 10, 14, 5, 12, 1),
			"日常全勤": Array(1900, 1450, 1100, 1030, 2, 5, 8, 7, 5, 4, 7),
			"日常及格": Array(1500, 1400, 1050, 870, 2, 5, 8, 4, 4, 4, 7),
			"人形普建": Array(-130, -130, -130, -30, 0.25, -1, 0, 0, 0, 0, 28),
			"人形重建": Array(-6000, -2000, -6000, -4000, -3, -1, 0, 0, 0, 0, 1),
			"装备普建": Array(-100, -151, -100, -50, 0, 0, -1, 0, 0, 0, 28),
			"500*4妖精": Array(-500, -500, -500, -500, -2, 0, -1, 0, 0, 0, 3),
			"2021妖精": Array(-2000, -500, -2000, -1000, -2, 0, -1, 0, 0, 0, 1),
			"0221妖精": Array(-500, -2000, -2000, -1000, -2, 0, -1, 0, 0, 0, 1),
			"2221妖精": Array(-2000, -2000, -2000, -1000, -2, 0, -1, 0, 0, 0, 1),
			"104E（搜救）": Array(-24, -84, -52, 4, 0.96, 0, 0, 0, 0, 0, 105),			
			"104E（无搜救）": Array(-24, -84, -52, 4, 0.64, 0, 0, 0, 0, 0, 1),
			"124E（搜救）": Array(-20, -80, -40, 4, 1, 0, 0, 0, 0, 0, 105),
			"124E（无搜救）": Array(-20, -80, -40, 4, 0.8, 0, 0, 0, 0, 0, 1),
			"71自律": Array(-270, -270, -270, -90, 0.5, 0, 0, 0, 0, 0, 140),
			"115自律": Array(-760, -760, -760, -250, 1, 0, 0, 0, 0, 0, 63),
			"前进营地": Array(-900, -900, -900, -300, 0, 0, 0, 0, 0, 0, 21),
			"0-1": Array(0, 145, 145, 0, 0, 0, 0, 50, 0, 20, 1),
			"0-2": Array(550, 0, 0, 350, 0, 50, 0, 0, 0, 0, 1),
			"0-3": Array(900, 900, 900, 250, 0, 0, 40, 40, 0, 0, 1),
			"0-4": Array(0, 1200, 800, 750, 0, 0, 0, 0, 100, 0, 1),
			"1-1": Array(10, 30, 15, 0, 0, 0, 0, 0, 0, 0, 1),
			"1-2": Array(0, 40, 60, 0, 0, 0, 0, 0, 0, 0, 1),
			"1-3": Array(30, 0, 30, 10, 0, 0, 0, 60, 0, 0, 1),
			"1-4": Array(160, 160, 0, 0, 0, 20, 0, 0, 0, 0, 1),
			"2-1": Array(100, 0, 0, 30, 0, 0, 0, 0, 0, 0, 1),
			"2-2": Array(60, 200, 80, 0, 0, 0, 0, 30, 0, 0, 1),
			"2-3": Array(10, 10, 10, 230, 0, 0, 0, 50, 0, 50, 1),
			"2-4": Array(0, 250, 600, 60, 0, 80, 0, 0, 0, 0, 1),
			"3-1": Array(50, 0, 75, 0, 0, 0, 0, 0, 0, 0, 1),
			"3-2": Array(0, 120, 70, 30, 0, 0, 0, 0, 0, 0, 1),
			"3-3": Array(0, 300, 0, 0, 0, 0, 0, 45, 0, 40, 1),
			"3-4": Array(0, 0, 300, 300, 0, 35, 40, 0, 0, 0, 1),
			"4-1": Array(0, 185, 185, 0, 0, 0, 20, 0, 0, 0, 1),
			"4-2": Array(0, 0, 0, 210, 0, 0, 0, 0, 0, 50, 1),
			"4-3": Array(800, 550, 0, 0, 0, 70, 0, 30, 0, 0, 1),
			"4-4": Array(400, 400, 400, 150, 0, 0, 0, 0, 0, 100, 1),
			"5-1": Array(0, 0, 100, 45, 0, 0, 0, 0, 0, 0, 1),
			"5-2": Array(0, 600, 300, 0, 0, 0, 0, 80, 0, 0, 1),
			"5-3": Array(800, 400, 400, 0, 0, 0, 50, 0, 0, 0, 1),
			"5-4": Array(100, 0, 0, 700, 0, 40, 0, 0, 0, 0, 1),
			"6-1": Array(300, 300, 0, 100, 0, 0, 0, 0, 0, 0, 1),
			"6-2": Array(0, 200, 550, 100, 0, 0, 0, 50, 0, 20, 1),
			"6-3": Array(0, 0, 200, 500, 0, 0, 60, 0, 0, 0, 1),
			"6-4": Array(800, 800, 800, 0, 0, 0, 0, 0, 80, 0, 1),
			"7-1": Array(650, 0, 650, 0, 0, 0, 0, 0, 0, 0, 1),
			"7-2": Array(0, 650, 0, 300, 0, 70, 0, 30, 0, 0, 1),
			"7-3": Array(900, 600, 600, 0, 0, 0, 70, 0, 0, 0, 1),
			"7-4": Array(250, 250, 250, 600, 0, 0, 0, 0, 0,80, 1),
			"8-1": Array(150, 150, 150, 0, 0, 0, 40, 0, 0, 0, 1),
			"8-2": Array(0, 0, 0, 450, 0, 0, 0, 80, 0, 0, 1),
			"8-3": Array(400, 800, 800, 0, 0, 0, 0, 30, 0, 60, 1),
			"8-4": Array(1500, 400, 400, 100, 0, 90, 0, 0, 0, 0, 1),
			"9-1": Array(0, 0, 100, 50, 0, 0, 0, 0, 0, 0, 1),
			"9-2": Array(180, 0, 180, 100, 0, 0, 0, 0, 0, 25, 1),
			"9-3": Array(750, 750, 0, 0, 0, 70, 0, 0, 0, 0, 1),
			"9-4": Array(500, 900, 900, 0, 0, 0, 100, 0, 0, 0, 1),
			"10-1": Array(140, 200, 0, 0, 0, 0, 0, 0, 0, 0, 1),
			"10-2": Array(0, 240, 180, 0, 0, 75, 0, 0, 0, 25, 1),
			"10-3": Array(0, 480, 480, 300, 0, 0, 0, 50, 0, 30, 1),
			"10-4": Array(660, 660, 660, 330, 0, 0, 100, 0, 0, 0, 1),
	//数据空缺						  人 装 修 采 建
	"11-1": Array(350, 1050, 0, 0, 0, 1, 1, 0, 0, 0, 1),
	"11-2": Array(360, 540, 540, 0, 0, 1, 0, 0, 0, 0, 1),
	"11-3": Array(0, 750, 1500, 250, 0, 0, 0, 1, 0, 0, 1),
	"11-4": Array(0, 1650, 0, 900, 0, 0, 0, 0, 0, 1, 1),
	"12-1": Array(0, 220, 220, 0, 0, 0, 1, 0, 0, 0, 1),
	"12-2": Array(360, 0, 0, 120, 0, 0, 0, 0, 0, 0, 1),
	"12-3": Array(800, 1200, 1200, 0, 0, 0, 0, 0, 0, 1, 1),
	"12-4": Array(1800, 0, 1800, 0, 0, 1, 0, 0, 0, 0, 1),
};
var log = new Array();
window.onload = function() {
	table = document.getElementById("table");
	pj = document.getElementById("project");
	percent = document.getElementById("percent");

	printtab();
	document.getElementById("num").onkeydown = function(event) {
		switch (event.keyCode) {
			case 13:
			sub()
			break;
			case 38:
			this.value -= -1;
			break;
			case 40:
			this.value -= 1;
			break;
			case 37:
			this.value -= 10;
			break;
			case 39:
			this.value -= -10;
			break;
			case 46:
			this.value = 0;
			break;
			default:
			console.log(event.keyCode);
		}
	}
	pj.select();
}
printtab = function() {
	table.innerHTML = defaulttable;
	var sum = new Array("总计", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	for (var i = 0; i < log.length; i++) {
		if (log[i] != undefined) {
			var tr = document.createElement("tr");
			var button = document.createElement("button");
			button.innerText = "删除";
			button.value = i;
			button.onclick = function() {
				delete log[this.value]
				printtab();
			}
			tr.append(name);
			for (var j = 0; j < log[i].length; j++) {
				var td = document.createElement("td");
				td.innerText = shortnum(log[i][j]);
				tr.append(td);
				if (j > 0 && j < sum.length) {
					sum[j] += log[i][j] * log[i][log[i].length - 1];
				}
			}
			tr.append(button);
			table.append(tr);
		}
	}
	var tr1 = document.createElement("tr");
	for (var i = 0; i < sum.length; i++) {
		var td = document.createElement("td");
		td.innerText = shortnum(sum[i]);
		tr1.append(td);
	}
	table.append(tr1);
}
sel = function(x) {
	pj.value = document.getElementById("select").value;
	check(x)
}
check = function(x) {
	if (pj.value.indexOf("-")==-1){
		for (var i = 2; i < inputbox.length; i++) {
			inputbox[i].value = data[x][i - 2];
			if (inputbox[i].value == "undefined"){
				inputbox[i].value = 0 ;
			}
		}
	} else {
		percent.value = percent.value==""?0.6:percent.value;
		for (var i = 2; i <=5 ; i++) {
			inputbox[i].value = data[x][i-2]*(1+percent.value/2);
		}
		s = data[x][5]+data[x][6]+data[x][7]+data[x][8]+data[x][9]
		for (var i = 7; i <=11 ; i++) {
			if (s!=0){
				inputbox[i].value = percent.value*data[x][i-2]/s+(1-percent.value)*data[x][i-2]/100;			
			}else {
				inputbox[i].value =0;
			}
		}
		inputbox[12].value = data[x][10];
	}
	document.getElementById("num").select();
}
sub = function() {
	if (pj.value.indexOf("-")!=-1){
		inputbox[12].value *=7;
	}
	var l = log.length;
	log[l] = new Array();
	log[l][0] = pj.value;
	for (var i = 2; i < inputbox.length; i++) {
		if (inputbox[i].value == "" ) {
			log[l][log[l].length] = 0;
		} else {
			log[l][log[l].length] = parseFloat(inputbox[i].value);
		}
	}
	console.log(log)
	printtab();
	reset();
	pj.select();
}
reset = function(x) {
	document.getElementById("select").value = "预设";
	for (var i = 0; i < inputbox.length; i++) {
		inputbox[i].value = "";
	}
}
shortnum = function(x) {
	if (!isNaN(x)) {
		if (x > 1000000 || x < -1000000) {
			return (x / 1000).toFixed(1) + "m";
		}
		if (x > 1000 || x < -1000) {
			return (x / 1000).toFixed(1) + "k";
		}
		if (x == parseInt(x) ) {
			return x;
		}
		if (x > 0 && x < 1){
			return x.toFixed(2);	
		}
		return x.toFixed(1);
	}
	return x
}

readme = function(){
	var x = document.getElementById("readme")
	if (x.style.display === "none") {
		x.style.display = "block";
	} else {
		x.style.display = "none";
	}
}


</script>
</head>
<body>	
	以周为单位统计收入支出：
	<br>
	<select id="select" onchange="sel(this.value);">
		<option>预设</option>
		<option>自动恢复</option>
		<option>周常全勤</option>
		<option>周常及格</option>
		<option>日常全勤</option>
		<option>日常及格</option>
		<option>人形普建</option>
		<option>人形重建</option>
		<option>装备普建</option>
		<option>500*4妖精</option>
		<option>2021妖精</option>
		<option>0221妖精</option>
		<option>2221妖精</option>
		<option>104E（搜救）</option>
		<option>104E（无搜救）</option>
		<option>124E（搜救）</option>
		<option>124E（无搜救）</option>
		<option>71自律</option>
		<option>115自律</option>
		<option>前进营地</option>
	</select>
	<input id="project" placeholder="项目" onchange="check(this.value)">
	<input id="percent" placeholder="大成功率">
	<br>
	<input placeholder="人力">
	<input placeholder="弹药">
	<input placeholder="口粮">
	<input placeholder="零件">
	<input placeholder="核心">
	<br>
	<input placeholder="人形契约">
	<input placeholder="装备契约">
	<input placeholder="快速修复">
	<input placeholder="采购币">
	<input placeholder="快速建造">	
	<br>
	<input id='num' placeholder="次数">
	<button id="sub" onclick="sub();">添加</button><button id="reset" onclick="reset();">重置</button>
	<br><br>
	<table id="table" >
		
	</table>
	<br>
	<button onclick="readme();">使用说明</button>
	<div id="readme" style="display: none;">
		1、10-4e方案为2保1四战，拆解收益认为平均每战10点；12-4e方案为2HG+1AR满配四战，拆解收益认为每战12点（3 4 2 1；均已整合入战斗消耗。12-4e出率采用：https://bbs.nga.cn/read.php?tid=19727351
		<br>
		2、日常和周常的收入来自先前的统计：https://bbs.nga.cn/read.php?pid=384172709
		<br>
		3、在“项目”框中输入后勤编号可以添加后勤，次数请填写“一天跑的次数”，计算器会自动乘7得到一周的次数
		<br>
		4、后勤票的获取权重来自：https://bbs.nga.cn/read.php?tid=10242318，11章后的票权重空缺，暂设定为仅大成功时有票。
		<br>
		5、“次数”框可以用方向键快速调整次数
		<br>
		6、建造公式为我自用公式，如果要升档或者调整请自行修改输入框的数值
		<br>
		7、未纳入考虑的有：营地收入、蚊子腿类收入、强化装备消耗、校准消耗、强化妖精消耗、完成日常所需的出战消耗、修理消耗等
	</div>
</body>

</html>